package com.poker.service;

import com.poker.entity.Banner;
import com.poker.repository.BannerRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class BannerService {

    @Resource
    private BannerRepository repository;

    public void delete(Banner banner) { repository.delete(banner); }

    public Banner getBySequence(String sequence) { return repository.findBySequence(sequence); }

    public Banner getById(String id) { return repository.getOne(id); }

    public void save(Banner banner) { repository.save(banner); }

    /**
     * @param: [page, size];
     * @return: org.springframework.data.domain.Page<Banner>;
     * @Description: 不带条件分页查询;
     */
    public Page<Banner> findBannerNoCriteria(Integer page, Integer size) {
        Pageable pageable = PageRequest.of(page, size, Sort.Direction.DESC, "createTime");

        return repository.findAll(pageable);
    }

}
